function initSystem() {
    //组织机构设置
    $('.top').click(function(){
        var str = $(this).attr('class');
        var param = $(this).attr('data-type');
        if(str.indexOf('on')== -1){
            $(this).siblings().removeClass('on')
            $(this).addClass('on');
        }
        if(param == 'unit'){
            $('.dept').hide();
            $('.userManage').hide();
            $('.unit').show();
        }else if(param == 'dept'){
            $('.unit').hide();
            $('.userManage').hide();
            $('.dept').show();
        }else if(param == 'user'){
            $('.unit').hide();
            $('.dept').hide();
            $('.userManage').show();
        }
        
        return;
    })
    
    //修改单位信息
    $(document).one('click', '.submitUnit', function () {
        var url = $(this).attr('data-url');
        var data = $('#form1').serialize();
        $.ajax({
                url: url,
                data: data,
                type: 'post',
                success: function (res) {
                    console.log(res);
                    layer.msg(res.info);
                }
        })
    })
    
    //选择部门主管、助理
    $(document).on('click', '.addUser', function () {
        var id = $(this).attr('data-id');
        var key = $(this).attr('data-key');
        var document_w = $(window).width();
        var document_h = $(window).height();
        var layer_w = '550';
        var layer_h = '550';
        var w = (document_w - layer_w) / 2;
        var h = (document_h - layer_h) / 2;
        layer.open({
            type: 2,
            title: [
                "选择人员",
                'background-color: #437dba;color:#fff;text-align:center;font-size:1.4em',
            ],
            area: [layer_w + 'px', layer_h + 'px'], //宽高
            offset: [h + 'px', w + 'px'], //弹出位置 [top,left]
            content: "/index.php/Home/Index/layer/type/1/id/" + id + "/key/" + key
        })
    })
    
    //删除单个用户
    $('body').on('click', '.delOperator', function () {
        $(this).parent('span').remove();
    })
    
    //新建部门
    $(document).one('click', '.saveDept', function () {
        var url = $(this).attr('data-url');
        var data = $('#form2').serialize();
        if($('input[name=DEPT_NO]').val() == ''){
            layer.msg('部门排序号不能为空！');
            return;
        }
        if($('input[name=DEPT_NAME]').val() == ''){
            layer.msg('部门名称不能为空！');
            return;
        }
        $.ajax({
                url: url,
                data: data,
                type: 'post',
                success: function (res) {
                    console.log(res);
                    if(res.status == 1){
                        var html = '<tr><td>'+res.new.dept_name+'</td><td>'+res.new.dept_no+'</td>';
                        html += '<td>'+res.new.tel_no+'</td><td>'+res.new.fax_no+'</td><td>'+res.new.dept_func+'</td>';
                        html += '<td><a class="delDept pointer" data-id="'+res.new.dept_id+'" data-url="delDept" style="color:#2a6496">删除</a></td></tr>'
                        $('.deptList').find('tr:last').after(html);
                        layer.msg(res.info);
                    }else{
                        layer.msg(res.info);
                    }
                }
        })
    })
    
    //删除部门(无刷新)
    $(document).on('click', '.delDept', function () {
        var dept_id = $(this).attr('data-id');
        var url = $(this).attr('data-url');
        $(this).parent().parent().remove();
        $.get(url,{dept_id:dept_id},function(res){
            console.log(res);
            layer.msg(res.info);
        })
    })
    
    //用户信息
    $('.deptName').click(function(){
        //点击当前部门将其他部门的样式取消
        $(this).siblings().children().children().css('color','#000');
        $(this).siblings().children().children().css('font-size','12px');
        
        //点击当前部门添加样式
        $(this).children().children().css('color','#0066cc');
        $(this).children().children().css('font-size','15px');
        
        //根据部门获取部门人员信息
        var dept_id = $(this).attr('data-id');
        $('.table1').hide();
        $('.detail').show();
        
        $.ajax({
                url: 'getDeptUser',
                data: {dept_id:dept_id},
                type: 'post',
                success: function (res) {
                    console.log(res);
                    if(res.status == 1){
                        var html = '<table class="table table-bordered deptList" width="100%" align="center"><tbody>';
                        html += '<thead style="background-color:#ecf3f9"><th width="10%">姓名</th><th width="15%">角色</th><th width="15%">辅助角色</th><th>性别</th><th width="10%">手机</th><th width="10%">邮箱</th></thead>'
                        for(var i=0;i<res.data.length;i++){
                            html += '<tr>';
                            html += '<td>'+res.data[i].user_name+'</td>';
                            html += '<td>'+res.data[i].user_priv+'</td>';
                            html += '<td>'+res.data[i].user_priv_other+'</td>';
                            html += '<td>'+res.data[i].sex+'</td>';
                            html += '<td>'+res.data[i].mobil_no+'</td>';
                            html += '<td>'+res.data[i].email+'</td>';
                            html += '</tr>';
                        }
                        html += '</tbody></table>';
                        $('.detail').html(html);
                    }else{
                        var noHtml = '<table class="table2" style="width:500px;margin:10% auto;border:1px solid #83ACCF;" cellspacing="0" cellpadding="0" align="center"><tbody>';
                        noHtml += '<tr class="head"><td class="left" style="background:#EBBF47;"></td><td class="center" style="background:#EBBF47;font-size:16px;font-weight:bolder;"><div class="title">提示</div></td><td class="right"></td></tr>';
                        noHtml += '<tr class="msg"><td class="left" style="height:90px;background-color: #FFF;"></td>';
                        noHtml += '<td class="center info" style="height:90px;background-color: #FFF;background: url(\'/Public/Admin/images/icon64_info.png\');background-position: 10px 10px;background-repeat: no-repeat;">';
                        noHtml += '<div class="msg-content" style="font-size: 16px;color: #EBBF47;">该部门还未添加用户</div></td><td class="right" style="height:90px;background-color: #fff;"></td></tr>';
                        noHtml += '<tr class="foot"><td class="left"></td><td class="center"><b></b></td><td class="right"></td></tr></tbody></table>';
                        $('.detail').html(noHtml);
                    }
                }
        })
        
    })
    
    //用户查询
    $('.searchUser').click(function(){
        var url = $(this).attr('data-url');
        var data = $('#userSearch').serialize();
        $('.table1').hide();
        $('.detail').show();
        $.ajax({
                url: url,
                data: data,
                type: 'post',
                success: function (res) {
                    console.log(res);
                    if(res.status == 1){
                        var html = '<table class="table table-bordered deptList" width="100%" align="center"><tbody>';
                        html += '<thead style="background-color:#ecf3f9"><th width="10%">姓名</th><th width="15%">角色</th><th width="15%">辅助角色</th><th>性别</th><th width="10%">手机</th><th width="10%">邮箱</th></thead>'
                        for(var i=0;i<res.data.length;i++){
                            html += '<tr>';
                            html += '<td>'+res.data[i].user_name+'</td>';
                            html += '<td>'+res.data[i].user_priv+'</td>';
                            html += '<td>'+res.data[i].user_priv_other+'</td>';
                            html += '<td>'+res.data[i].sex+'</td>';
                            html += '<td>'+res.data[i].mobil_no+'</td>';
                            html += '<td>'+res.data[i].email+'</td>';
                            html += '</tr>';
                        }
                        html += '</tbody></table>';
                        $('.detail').html(html);
                    }else{
                        var noHtml = '<table class="table2" style="width:500px;margin:10% auto;border:1px solid #83ACCF;" cellspacing="0" cellpadding="0" align="center"><tbody>';
                        noHtml += '<tr class="head"><td class="left" style="background:#EBBF47;"></td><td class="center" style="background:#EBBF47;font-size:16px;font-weight:bolder;"><div class="title">提示</div></td><td class="right"></td></tr>';
                        noHtml += '<tr class="msg"><td class="left" style="height:90px;background-color: #FFF;"></td>';
                        noHtml += '<td class="center info" style="height:90px;background-color: #FFF;background: url(\'/Public/Admin/images/icon64_info.png\');background-position: 10px 10px;background-repeat: no-repeat;">';
                        noHtml += '<div class="msg-content" style="font-size: 16px;color: #EBBF47;">无符合条件的用户</div></td><td class="right" style="height:90px;background-color: #fff;"></td></tr>';
                        noHtml += '<tr class="foot"><td class="left"></td><td class="center"><b></b></td><td class="right"></td></tr></tbody></table>';
                        $('.detail').html(noHtml);
                    }
                }
        })
    })
    
    $(document).on('click', '.search_user', function () {
        $('.detail').hide();
        $('.detail').html('');
        $('.table1').show();
    })
}
